package com.helsinki.mapper;

import com.helsinki.pojo.Orders;
import com.helsinki.pojo.Product;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface OrdersMapper {
    @Results(id = "OrdersMap", value = {
            @Result(id = true, column = "id", property = "id"),
            @Result(column = "orderNum", property = "orderNum"),
            @Result(column = "orderTime", property = "orderTime"),
            @Result(column = "orderStatus", property = "orderStatus"),
            @Result(column = "peopleCount", property = "peopleCount"),
            @Result(column = "payType", property = "payType"),
            @Result(column = "orderDesc", property = "orderDesc"),
            // 1.和产品的关系, 1-1关系
            @Result(column = "productId", property = "product",
                    one = @One(select = "com.helsinki.mapper.ProductMapper.findById")),
            // 2.和会员的关系, 1-1关系
            @Result(column = "memberId", property = "member",
                    one = @One(select = "com.helsinki.mapper.MemberMapper.findById")),
            // 3.和游客的关系, 1-n关系
            @Result(column = "id", property = "travellers",
                    many = @Many(select = "com.helsinki.mapper.TravellerMapper.findByOrderId"))
    })
    @Select("select * from orders where id = #{id}")
    Orders findById(String id);

    // 查询所有商品
    @ResultMap("OrdersMap")
    @Select("select * from orders")
    List<Orders> findAll();


    //更改订单状态
    @Update("update orders set orderStatus = #{status} where id = #{id}")
    void updateStatus(@Param("id") String id,
                      @Param("status") int status);
}
